import {Action, Actor} from 'iflux2'

export default class RefundSetup extends Actor{
  defaultState() {
    return {
      afterSaleState: 0,
      afterSaleLimit: 0,
      afterSaleContent: '',
      afterSaleOptionInfos: [],
      modalVisb: false,
      editorInfo: {}
    }
  }
  @Action('setup-init')
  setupInit(state, data) {
    return state.merge(data);
  }
  @Action('handle-basic-setup')
  onBasicSetup(state, data) {
    return state.merge(data);
  }
  @Action('cancel-editor')
  optsCancelEditor(state) {
    return state.update('modalVisb', (v)=>!v)
  }
  @Action('edit-name')
  optsEditor(state,data) {
    return state.update('editorInfo', (v)=>v.merge(data))
  }
  @Action('editor-contents')
  showEditor(state, data) {
    return state.merge(data)
  } 
  @Action('edit-option')
  editOption(state, data) {
    return state.update('editorInfo', (v)=>v.merge(data))
  }
  @Action('option-edit-sucess')
  optionSetup(state, {attrId, isChecked, ...rest}) {
    return state.withMutations((cursor)=>{
      if(!isChecked){
        cursor.update('modalVisb', (v)=>!v)
      }
      cursor.update('afterSaleOptionInfos', (list)=>{
        return list.map((v)=>{
          if(v.get('attrId') == attrId){
            return v.merge(rest)
          }else{
            return v
          }
        })
      })
    });
  }
}